#ifndef FUNC_H
#define FUNC_H

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/mman.h>
#include <sys/select.h>
#include <time.h>
#include <sys/wait.h>
#include <dirent.h>
#include <syslog.h>
#include <sys/shm.h>
#include <sys/ipc.h>
#include <signal.h>
#include <sys/time.h>
#include <pthread.h>
#include <arpa/inet.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <sys/epoll.h>
#include <sys/sendfile.h>
#include <netinet/in.h>
#include <netinet/ip.h>
#include <errno.h>
#include <pwd.h>
#include <grp.h>
#include <ctype.h>
#include <stdint.h>
#include <stdbool.h>
#include <shadow.h>

#define ARGS_CHECK(argc, num){if(argc != num){fprintf(stderr, "args error !\n"); return -1;} }
#define ERROR_CHECK(ret, num, msg){if(ret==num){perror(msg); return -1;}}
#define THREAD_ERROR_CHECK(ret, msg){if(ret!=0){fprintf(stderr, "%s:%s \n", msg,strerror(ret));}}
// 将整数转换为字符串
static inline char* int_to_str(int num, char* buffer, size_t buffer_size) {
    snprintf(buffer, buffer_size, "%d", num);
    return buffer;
}
// 定义日志宏
#define SYSTEM_LOG_CLIENT_REQUEST(syslog_fd, msg) do { \
    char log_buffer[256]; \
    char line_str[16]; \
    time_t now = time(NULL); \
    struct tm *tm_info = localtime(&now); \
    strftime(log_buffer, sizeof(log_buffer), "[%Y-%m-%d %H:%M:%S] ", tm_info); \
    strcat(log_buffer, "line:"); \
    strcat(log_buffer, int_to_str(__LINE__, line_str, sizeof(line_str))); \
    strcat(log_buffer, "\tfunc:"); \
    strcat(log_buffer, __FUNCTION__); \
    strcat(log_buffer, "\tfile:"); \
    strcat(log_buffer, __FILE__); \
    strcat(log_buffer, "\t"); \
    strcat(log_buffer, msg); \
    strcat(log_buffer, "\n"); \
    write(syslog_fd, log_buffer, strlen(log_buffer)); \
} while (0)
#endif
